#region Using References

using System.Collections.Generic;
using System.IO;
using System.Linq;

#endregion

namespace Beaker.Services.FileSystem.Physical
{
	public abstract class FolderBase
		: IFolder
	{
		private readonly FolderBase _parent;

		protected FolderBase( FolderBase parent )
		{
			_parent = parent;
		}

		/// <summary>
		/// Gets the name of the entry
		/// </summary>
		public abstract string Name { get; }

		/// <summary>
		/// Get the folder this entry is in.
		/// </summary>
		public IFolder ParentFolder
		{
			get { return _parent; }
		}

		/// <summary>
		/// Gets the files in this folder.
		/// </summary>
		/// <param name="option">The options for searching for files.</param>
		/// <returns>
		/// A sequence of files.
		/// </returns>
		public IEnumerable<IFile> GetFiles()
		{
			return
				GetEntries()
					.OfType<IFile>();
		}

		/// <summary>
		/// Gets the file with the given name.
		/// </summary>
		/// <param name="fileName">The name of the file to get.</param>
		/// <returns>The file with the given name, or <c>null</c> when it could not be found.</returns>
		public abstract IFile GetFile( string fileName );

		/// <summary>
		/// Gets the folders in this folder.
		/// </summary>
		/// <param name="option">The options for searching for folders.</param>
		/// <returns>
		/// A sequence of folders.
		/// </returns>
		public IEnumerable<IFolder> GetFolders()
		{
			return
				GetEntries()
					.OfType<IFolder>();
		}

		/// <summary>
		/// Gets the folder with the given name.
		/// </summary>
		/// <param name="folderName">The name of the folder to get.</param>
		/// <returns>The folder with the given name, or <c>null</c> when it could not be found.</returns>
		public abstract IFolder GetFolder( string folderName );

		/// <summary>
		/// Gets the entires in this folder.
		/// </summary>
		/// <param name="option">The options for searching for items.</param>
		/// <returns>
		/// A sequence of items.
		/// </returns>
		public abstract IEnumerable<IFileSystemEntry> GetEntries();

		/// <summary>
		/// Gets the entry with the given name in this folder.
		/// </summary>
		/// <param name="entryName">Name of the entry to get.</param>
		/// <returns>The entry with the given name, or <c>null</c> when it could not be found.</returns>
		public abstract IFileSystemEntry GetEntry( string entryName );
	}
}